#include "data_es.hpp"
#include <gflags/gflags.h>
#include <thread>
DEFINE_bool(run_mode, false, "程序的运行模式，false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es客户端url");

// 在test中往es中添加数据后需要删除

int main(int argc, char *argv[])
{

    google::ParseCommandLineFlags(&argc, &argv, true);
    bite_im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    std::vector<std::string> host_list = {FLAGS_es_host};
    auto es_client = bite_im::ElasticFactory::create(host_list);
    auto es_message = std::make_shared<bite_im::ESMessage>(es_client);

    // 如果appendData和serarch时间差较小，会导致无法查询
    // search的时候appendData还没有构建好

    es_message->createIndex();
    es_message->appendData("ad3a-7782-650d-0000", "消息id-1", 1727967611, "会话-1", "你吃了吗");
    es_message->appendData("1f5d-e72e-e845-0001", "消息id-2", 1727967731, "会话-1", "吃饭了");
    es_message->appendData("6771-9495-fdb4-0002", "消息id-3", 1727968031, "会话-1", "吃了蛋炒饭");
    es_message->appendData("5d71-92bf-2176-0003", "消息id-4", 1727968271, "会话-1", "吃鸡蛋");

    es_message->appendData("3b70-49c7-dfe4-0004", "消息id-5", 1727960831, "会话-2", "鸡你太美了");
    es_message->appendData("5b54-cf54-dfe7-0005", "消息id-6", 1727960831, "会话-2", "饭鸡");

    std::this_thread::sleep_for(std::chrono::seconds(5));

    // auto ret1 = es_message->search("吃", "会话1");
    // for (auto message : ret1)
    // {
    //     std::cout << message.user_id() << std::endl;
    //     std::cout << message.content() << std::endl;
    //     std::cout << boost::posix_time::to_simple_string(message.create_time()) << std::endl;
    //     std::cout << message.session_id() << std::endl;
    // }
    // std::cout << std::endl;
    // auto ret2 = es_message->searchAll("蛋");
    // for (auto message : ret2)
    // {
    //     std::cout << message.user_id() << std::endl;
    //     std::cout << message.content() << std::endl;
    //     std::cout << boost::posix_time::to_simple_string(message.create_time()) << std::endl;
    //     std::cout << message.session_id() << std::endl;
    // }
    // std::cout << std::endl;
}